package com.lenovo.smarttraffic.ui.activity.stage2;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.widget.ListView;

import com.google.gson.Gson;
import com.lenovo.smarttraffic.MainActivity;
import com.lenovo.smarttraffic.R;
import com.lenovo.smarttraffic.bean.CarInfo;
import com.lenovo.smarttraffic.bean.UserBean;
import com.lenovo.smarttraffic.ui.activity.BaseActivity;
import com.lenovo.smarttraffic.ui.adapter.ETCMoneyAdapter;
import com.lenovo.smarttraffic.util.HttpUtils;

public class ETCMoneyActivity extends BaseActivity {

    private ListView mListView;
    private ETCMoneyAdapter adapter;

    @Override
    protected int getLayout() {
        return R.layout.activity_etc_money;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        initView();
        initData();
    }

    public void initView() {
        Toolbar mToolbar = findViewById(R.id.toolbar);
        mToolbar.setNavigationOnClickListener(view -> finish());

        mListView = findViewById(R.id.listview);
    }

    public void initData() {
        HttpUtils.post(this, "get_car_info",
                new HttpUtils().setParam("UserName", MainActivity.userName),
                response -> HttpUtils.post(this, "get_all_user_info",
                        new HttpUtils().setParam("UserName", MainActivity.userName),
                        response2 -> {
                            adapter = new ETCMoneyAdapter(ETCMoneyActivity.this, new Gson().fromJson(response.toString(), CarInfo.class)
                                    , new Gson().fromJson(response2.toString(), UserBean.class));
                            mListView.setAdapter(adapter);
                        }));
    }

}
